home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-04-03 | 11.4 KB | 409 lines |
- /*
- * ServletContext.java -- Interface for class containing servlet context data
- *
- * Copyright (c) 1998, 1999 by Free Software Foundation, Inc.
- * Written by Paul Siegmann (pauls@euronet.nl)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License as published
- * by the Free Software Foundation, version 2. (see COPYING.LIB)
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
- */
-
- package javax.servlet;
-
- import java.lang.Exception;
- import java.io.InputStream;
- import java.net.URL;
- import java.net.MalformedURLException;
- import java.util.Enumeration;
-
- /**
- * A class created by the server to give servlets access to certain
- * environment related objects and methods.<BR>
- * It contains standard information like the names of all the servlets,
- * two kinds of log methods, the server name, etc.<BR>
- * The server can also store extra information here in the form
- * of {String, Object} pairs.
- * Different servlets can live in different ServletContexts,
- * but a servlet engine can group related Servlets in the same
- * ServletContext.<BR>
- * Servlet specific information can be transferred to a servlet using
- * a class implementing the ServletConfig interface.<BR>
- *
- #ifdef SERVLET_2_0
- * @version Servlet API 2.0
- #endif
- #ifdef SERVLET_2_1
- * @version Servlet API 2.1
- #endif
- #ifdef SERVLET_2_2
- * @version Servlet API 2.2
- #endif
- * @since Servlet API 1.0
- * @author Paul Siegmann (pauls@euronet.nl)
- */
- public interface ServletContext
- {
- /**
- * Gets the value of a named attribute
- *
- * @since Servlet API 1.0
- *
- * @param name the name of the attribute
- * @return the value of the attribute or null if there is no attribute with
- * this name
- */
- Object getAttribute (String name);
-
-
- #ifdef SERVLET_2_0
- #else
- /**
- * Gets an enumeration containing all the attribute names
- *
- * @since Servlet API 2.1
- *
- * @return The enumeration containing all the attribute names
- */
- Enumeration getAttributeNames ();
-
-
- /**
- * Gives the <code>ServletContext</code> of another servlet indicated by
- * the <code>UriPath</code> on the same server. For security reasons this
- * can return null even if there is an active servlet at that location.
- * This can then be used to set attributes in the context of another
- * servlet.
- * @see javax.servlet.ServletContext#setAttribute(java.lang.String, java.lang.Object)
- *
- * @since Servlet API 2.1
- *
- * @param UriPath The path to the servlet,
- * such as <code>/servlet/ShowBook</code>
- * @return ServletContext of the requested servlet or null if there is no
- * servlet at the requested <code>UriPath</code> or when it is unavailable
- * due to security restrictions
- */
- ServletContext getContext (String UriPath);
-
-
- /**
- * Major version number of the Servlet API the servlet engine supports.
- *
- * @since Servlet API 2.1
- *
- * @return 2 if the 2.1 Servlet API is supported
- */
- int getMajorVersion ();
-
- /**
- * Minor version number of the Servlet API the servlet engine supports.
- *
- * @since Servlet API 2.1
- *
- * @return 1 if the 2.1 Servlet API is supported
- */
- int getMinorVersion ();
- #endif
-
-
- /**
- * Gives the mimetype of the requested file
- *
- * @since Servlet API 1.0
- *
- * @param filename the file
- * @return a String containing the mime type
- * or null if the mime type cannot be determined
- */
- String getMimeType (String filename);
-
-
- /**
- * Translates the requested virtual path to the real filesystem path
- * using the servers knowledge of the document root.
- #ifdef SERVLET_2_0
- #else
- * Use the <code>getResource</code> and <code>getResourceAsStream</code>
- * methods to access the original object in a more abstract way not tied to
- * the filesystem.
- * @see javax.servlet.ServletContext#getResource(java.lang.String)
- * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)
- #endif
- *
- * @since Servlet API 1.0
- *
- * @param virtualPath the path to be translated
- * (e.g. <code>/graphics/baby-gnu.png</code>)
- * @return the translated real filesystem path
- * or null if the real system path cannot be found
- */
- String getRealPath (String virtualPath);
-
-
- #ifdef SERVLET_2_0
- #else
- /**
- * Translates the requested virtual path to an URL object that can be
- * accesed by the servlet. This is more generic than the
- * <code>getRealPath</code> method since it is not tied to the local
- * filesystem. This means that a servlet can access the resource even when
- * loaded in a servlet engine on a different machine. The servlet engine
- * should make sure that the appropriate <code>URLStreamHandlers</code> and
- * <code>URLConnection</code> classes are implemented to acces to resource.
- * <p>
- * This can also be used to write to a resource if the resource
- * (<code>URLConnection</code>) supports it. The following example gives
- * you an <code>OutputStream</code>:<br>
- * <p>
- * <code>
- * URLConnection con = getResource("/logs/mylog.txt").openConnection();<br>
- * con.setDoOutput(true);<br>
- * OutputStream out = con.getOutputStream();<br>
- * </code>
- * <p>
- * Note that a <code>ServerContext</code> does not have to have access to
- * the complete servers document space and is allowed to return null even
- * for valid virtual paths.
- * <p>
- * Note that according to the 2.1 API documentation this method can throw
- * a MalformedURLException. But according to the official spec it does not
- * throw any exceptions.
- *
- * @since Servlet API 2.1
- *
- * @see java.net.URL#openConnection()
- * @see java.net.URLConnection#setDoOutput(boolean)
- * @see java.net.URLConnection#getOutputStream()
- *
- * @param virtualPath the path to the requested resource
- * (e.g. <code>/philosophy/words-to-avoid.html</code>)
- * @return the URL that can be used to access the resource
- * or null if the resource cannot be found
- */
- URL getResource (String virtualPath) throws MalformedURLException;
-
- #endif
-
- #ifdef SERVLET_2_2
-
- /**
- * XXX
- */
- URL getResource (String virtualPath, Locale locale) throws MalformedURLException;
-
- #endif
-
- #ifdef SERVLET_2_0
- #else
-
- /**
- * A convenience method for
- * <code>getResource(virtualPath).openStream()</code>.
- * But the servlet engine is allowed to implement is in a more efficient
- * way.
- *
- * @see javax.servlet.ServletContext#getResource(java.lang.String)
- * @see java.net.URL#openStream()
- *
- * @since Servlet API 2.1
- *
- * @param virtualPath the path to the requested resource
- * (e.g. <code>/philosophy/words-to-avoid.html</code>)
- * @return the InputStream that can be used to read the resource
- * or null if the resource cannot be found
- */
- InputStream getResourceAsStream(String virtualPath);
-
- #endif
-
- #ifdef SERVLET_2_2
-
- /**
- * XXX
- */
- URL getResourceAsStream(String virtualPath, Locale locale) throws MalformedURLException;
-
- #endif
-
- #ifdef SERVLET_2_0
- #else
-
- /**
- * Returns a <code>RequestDispatcher</code> to forward requests or
- * include responses from another (active) resource. Some resources can also
- * be accessed by the <code>getResource</code> method.
- *
- * @see javax.servlet.ServletContext#getResource(java.lang.String)
- *
- * @since Servlet API 2.1
- *
- * @param UriPath the path to another (active) resource
- * (e.g. <code>/servlet/OtherServlet</code>)
- * @return an <code>RequestDispatcher</code> for the (active) resource
- * found at <code>UriPath</code>
- */
- RequestDispatcher getRequestDispatcher (String UriPath);
- #endif
-
- #ifdef SERVLET_2_2
-
- /**
- * XXX
- */
- RequestDispatcher getNamedDispatcher(String name);
-
- #endif
-
- /**
- * A server supplied string containing the server name, version number, etc
- *
- * @since Servlet API 1.0
- *
- * @return the string
- */
- String getServerInfo ();
-
- #ifdef SERVLET_2_2
-
- /**
- * XXX
- */
- String getInitParamaterName(String name);
-
- /**
- * XXX
- */
- Enumeration getInitParamaterNames();
-
- #endif
-
- /**
- * Writes a message to the log
- *
- * @since Servlet API 1.0
- *
- * @param message the message to write
- */
- void log (String message);
-
-
- #ifdef SERVLET_2_0
- #else
- /**
- * Writes an exception + message to the log
- *
- * @since Servlet API 2.1
- *
- * @param t the exception
- * @param message the message
- */
- void log (String message, Throwable t);
- #endif
-
-
- /**
- * Writes an exception + message to the log
- *
- #ifdef SERVLET_2_0
- #else
- * @deprecated Use <code>log(String, Throwable)</code> which is more
- * general.
- *
- * @see javax.servlet.ServletContext#log(java.lang.String, java.lang.Throwable)
- #endif
- * @since Servlet API 2.0
- *
- * @param exception the exception
- * @param message the message
- */
- void log (Exception exception, String message);
-
-
- #ifdef SERVLET_2_0
- #else
- /**
- * Puts a named object into the <code>ServletContext</code>.
- * Can be used to communicate with other servlets in this
- * <code>ServletContext</code>. The names used must follow the conventions
- * used for naming java packages.
- *
- * @since Servlet API 2.1
- *
- * @param name - which is used to refer to this object
- * @param object - which should be returned when somebody calls
- * <code>getAttribute(name)</code>
- * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
- */
- void setAttribute(String name, Object o);
-
-
- /**
- * Removes the named object from the <code>ServletContext</code>
- *
- * @since Servlet API 2.1
- *
- * @param name The name which was used to set the object with
- * <code>setObject</code>
- */
- void removeAttribute(String name);
- #endif
-
-
- /**
- * Gets a specific servlet by name. The Servlet is guaranteed to accept
- * service requests.
- #ifdef SERVLET_2_0
- #else
- * @deprecated Always returns null. Since the servlet engine cannot know
- * if a servlet ever gives up the reference to another servlet it could
- * never destroy the servlet after this call.
- * Only the servlet engine should have references to Servlets.
- #endif
- *
- * @since Servlet API 1.0
- *
- * @param name the name of the wanted servlet
- * @return null, used to return the servlet or null if not loaded.
- * @exception ServletException if a servlet related error occured
- */
- Servlet getServlet (String name) throws ServletException;
-
-
- /**
- * Gets all servlets
- * @deprecated Always returns an empty Enumeration.
- * Only the servlet engine should have references to Servlets.
- *
- * @since Servlet API 1.0
- *
- * @return Empty Enumeration, used to return an enumeration containing all
- * loaded servlets including the calling servlet.
- */
- Enumeration getServlets ();
-
-
- /**
- * Gets all servlet names
- #ifdef SERVLET_2_0
- #else
- * @deprecated Always returns an empty Enumeration.
- * Only the servlet engine should have references to Servlets.
- #endif
- * @since Servlet API 2.0
- *
- * @return Empty Enumeration, used to return an enumeration containing all
- * loaded servlet names including the calling servlet name
- */
- Enumeration getServletNames ();
- }
-